﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using Lamex.Library;
using System.IO;
using DevExpress.Utils;

namespace Lamex.mMES.UI
{
    public partial class frmMES_Operation_PPT : Form
    {
        //DevExpress 组合控件系列（3）： ImageSlider+GridControl 简单的图片查看器（A）
        //https://blog.csdn.net/m0_37688683/article/details/88313916?depth_1-utm_source=distribute.pc_relevant.none-task&utm_source=distribute.pc_relevant.none-task

        //devexpress控件layoutview特效之一旋转木马的实现
        //https://www.cnblogs.com/ManchesterUnitedFootballClub/p/4635775.html

        public frmMES_Operation_PPT()
        {
            InitializeComponent();
            this.Load += (s, e) =>
            {
                DataShow();
                ControlEvent();
            };
        }

        private void frmMES_Operation_PPT_Load(object sender, EventArgs e)
        {
            layoutView1.OptionsBehavior.Editable = false;
            layoutView1.OptionsCustomization.AllowFilter = false;
            layoutView1.OptionsCustomization.AllowSort = false;
            layoutView1.OptionsView.ShowCardBorderIfCaptionHidden = false;
            layoutView1.OptionsView.ShowCardCaption = false;
            layoutView1.OptionsView.ShowCardLines = false;
            layoutView1.OptionsView.ShowHeaderPanel = false;
            layoutView1.OptionsView.ViewMode = DevExpress.XtraGrid.Views.Layout.LayoutViewMode.Column;

            //toolTipController1
        }

        private void frmMES_Operation_PPT_Resize(object sender, EventArgs e)
        {
            //sbtnFirst.Location = new Point((this.Width - 81 * 5 - 60) / 2, 5);
            sbtnFirst.Left = (this.Width - 81 * 5 - 60) / 2;
            sbtnPrev.Left = sbtnFirst.Left + 81 * 1;
            sbtnNext.Left = sbtnFirst.Left + 81 * 2;
            sbtnLast.Left = sbtnFirst.Left + 81 * 3;
            sbtnDownload.Left = sbtnFirst.Left + 81 * 4;
            sbtnClose.Left = sbtnFirst.Left + 81 * 5;
        }

        #region 绑定数据
        /// <summary>
        /// 绑定数据
        /// </summary>
        private void DataShow()
        {
            //var path = Application.StartupPath + @"\Image";
            //var path = @"\\Tx-fs10\tx-fs1\LAMEX\MES\Resources\新建文件夹\Parts";
            var path = @"\\Tx-fs10\tx-fs1\LAMEX\MES\Resources\PPT\生产运作管理系统介绍";

            var files = new DirectoryInfo(path).GetFiles();
            var data = files.Select(d =>
            {
                this.imageSlider1.Images.Add(Image.FromFile(d.FullName));
                return new { Name = d.Name, Image = Image.FromFile(d.FullName), Paths = d.FullName };
            });

            this.gridControl1.BeginUpdate();
            this.gridControl1.DataSource = data;
            this.gridControl1.EndUpdate();
        }

        #endregion

        #region 控件的委托事件

        /// <summary>
        /// 控件的委托事件
        /// </summary>
        private void ControlEvent()
        {
            /*卡片的点击事件*/
            this.layoutView1.CardClick += (s, e) =>
            {
                if (e.Button == MouseButtons.Left)
                    this.imageSlider1.CurrentImageIndex = e.Card.RowHandle;
            };

            this.sbtnFirst.Click += (s, e) =>
            {
                this.imageSlider1.SlideFirst();
            };
            this.sbtnPrev.Click += (s, e) =>
            {
                this.imageSlider1.SlidePrev();
            };
            this.sbtnNext.Click += (s, e) =>
            {
                this.imageSlider1.SlideNext();
            };
            this.sbtnLast.Click += (s, e) =>
            {
                this.imageSlider1.SlideLast();
            };
            this.sbtnClose.Click += (s, e) =>
            {
                this.Close();
            };

            this.sbtnDownload.Click += (s, e) =>
            {
                var path = (string)this.layoutView1.GetRowCellValue(this.imageSlider1.CurrentImageIndex, "Paths");
                var name = this.layoutView1.GetRowCellValue(this.imageSlider1.CurrentImageIndex, "Name");

                SaveFileDialog sf = new SaveFileDialog();
                sf.Title = "选择保存文件路径";
                //sf.Filter = "图像文件(*.jpg)|*.jpg;";
                sf.Filter = "图像文件(*.png)|*.png;";
                sf.FileName = name.ToString();
                sf.AddExtension = true;/*自动添加扩展名*/
                if (sf.ShowDialog() == DialogResult.OK)
                {
                    File.Copy(path, sf.FileName, true);//目录重命名见下面代码
                }
            };
        }

        #endregion

        private void 隐藏缩略图ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            gridControl1.Visible = false;
        }

        private void 显示缩略图ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            gridControl1.Visible = true;
        }

    //    private void toolTipController1_GetActiveObjectInfo(object sender, DevExpress.Utils.ToolTipControllerGetActiveObjectInfoEventArgs e)
    //    {
    //        //ToolTipController与GridControl的连用
    //        //鼠标指向表格时 显示更多信息 toolTipController1
    //        //https://www.it610.com/article/1296112.htm

    //        if (e.SelectedControl != imageSlider1) return;
    //        ToolTipControlInfo info = null;

    //        object o = "AA";
    //        StringBuilder sb = new StringBuilder();

    //        sb.AppendLine("行数据基本信息:");
    //        sb.AppendFormat("{0}:{1}\r\n", "1", "2");
    //        info = new ToolTipControlInfo(o, sb.ToString());
         
    //        if (info != null)
    //        {
    //            e.Info = info;
    //        }
    //    }
    }
}